package com.example.fw;

import java.util.Properties;

import org.netbeans.jemmy.ClassReference;
import org.netbeans.jemmy.operators.JFrameOperator;

public class ApplicationManager {
	
	private Properties props;
	private FolderHelper folderHelper;
	private MenuHelper menuHelper;
	private TreeHelper treeHelper;
	private JFrameOperator mainFrame;
	private static ApplicationManager singleton;
	
	public static ApplicationManager getInstance(){
	if (singleton == null)
		{singleton = new ApplicationManager();}
	return singleton;
	}
	
	public void stop(){ 
		getApplication().requestClose();
	}
	
	public void setProperties (Properties props){
		this.props = props;
	}
	
	public String setProperty (String key){
		return props.getProperty(key);
	}
	
	public String getProperty (String key, String defaultValue){
		return props.getProperty(key, defaultValue);
	}

	public FolderHelper getFolderHelper() {
		if (folderHelper == null){
		folderHelper = new FolderHelper(this);
		}
				
		return folderHelper;
	}

	public JFrameOperator getApplication() {
		
		if (mainFrame == null){
		
		try {
			new ClassReference("addressbook.AddressBookFrame").startApplication();
			mainFrame = new JFrameOperator("jAddressBook");
		
		} catch (Exception e) {
			e.printStackTrace();
		}
		}
		return mainFrame;
	}

	public MenuHelper getMenuHelper() {
		if (menuHelper == null){
			menuHelper = new MenuHelper(this);
			}
					
			return menuHelper;
	}

	public TreeHelper getTreeHelper() {
		if (treeHelper == null){
			treeHelper = new TreeHelper(this);
			}
					
			return treeHelper;
	}
	
	
	
}